#include <bits/stdc++.h>
using namespace std;
/*
 * @lc app=leetcode.cn id=3 lang=cpp
 *
 * [3] 无重复字符的最长子串
 */

// @lc code=start
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_set<char> record;
        int front = 0, res = 0; 
        for (int i = 0; i < s.size(); i++) {
            while (record.count(s[i]) > 0) {
                record.erase(s[front]);
                front++;
            }
            record.insert(s[i]);
            res = max(res, i - front + 1);
        }
        return res;
    }
};
// @lc code=end

